/*
 * Created on Feb 26, 2005
 */
package com.scalar.chiptrack.finance.openpo.actioncommands;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.scalar.ScalarException;
import com.scalar.chiptrack.ChipTrackExtendedAction;
import com.scalar.chiptrack.finance.openpo.dao.PurchaseOrderDAO;
import com.scalar.chiptrack.finance.openpo.forms.PurchaseOrderReceiptForm;
import com.scalar.chiptrack.users.ErrorReport;
import com.scalar.chiptrack.utils.Logger;

/**
 * @author Ravikanth
**/
public class PurchaseOrderReceiptEditCommand extends ChipTrackExtendedAction
{
	/* 
	 * Edit Command
	 */
	public ActionForward executeRequest( ActionMapping mapping,	ActionForm form, HttpServletRequest request, HttpServletResponse response)throws Exception
	{        
		HashMap errors              = new HashMap();
		HashMap info                = new HashMap();
		PurchaseOrderReceiptForm purchaseOrderReceiptForm = ( PurchaseOrderReceiptForm ) form;
		String actionForward 		= "receiptSearch";
		HttpSession mSession 		= request.getSession();
		
		try
		{
			if( purchaseOrderReceiptForm != null )
			{
				actionForward = "receipt";
			}
			else
			{
				throw new ScalarException( ERROR_LOADING_RECEIVINGS_TRANSACTION_INFORMATION, null );
			}
            request.setAttribute("poTaxTypes", PurchaseOrderDAO.loadPOTaxesList() );            

		}
		catch ( Exception e )
		{
			Logger.error( ERROR_LOADING_RECEIVINGS_TRANSACTION_INFORMATION, e );
			errors.put( ERROR_INTERNAL_SERVER_ERROR, ERROR_LOADING_RECEIVINGS_TRANSACTION_INFORMATION );
			mSession.setAttribute( ERROR_REPORT_OBJECT, new ErrorReport( ERROR_LOADING_RECEIVINGS_TRANSACTION_INFORMATION, e ) );
			actionForward = "receiptSearch";
			request.setAttribute( "vendorsList", PurchaseOrderDAO.loadAllVendors() );
			request.setAttribute( "yearList", PurchaseOrderDAO.getYearList () );
			request.setAttribute( "productList", PurchaseOrderDAO.loadPOProductsList() );
		}

		request.setAttribute( ERROR_MESSAGES, errors );
		request.setAttribute( INFO_MESSAGES, info );
		return mapping.findForward( actionForward );
	}
}
